/*
 * @file    rotate_array.cpp
 * @author  edward <libo@tencent.com>
 * @date    2013-04-05
 * @brief   
 * */

#include <iostream>
#include <string.h>

void reverse_string(char* str, int n, int m) {
    char* l = str + n;
    char* r = str + m;
    while(l < r) {
       char tmp = *l;
       *l = *r;
       *r = tmp;
       ++l;
       --r;
    }
}

void roate_string(char* str, int k) {
    int sz = strlen(str);
    reverse_string(str, 0, sz - 1);
    reverse_string(str, 0, k - 1);
    reverse_string(str, k, sz -1);
}

int main() {
    char tmp[] = "helllo";
    roate_string(tmp, 2);
    std::cout << tmp;
}
